/*
 * SPDX-License-Identifier: GPL-2.0
 * RPMB 安全协议接口定义
 * 衍生自 mmc-utils 项目，遵循 GPLv2 协议。
 */

#ifndef __RPMB_H__
#define __RPMB_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdint.h>
#include <assert.h>
#include <linux/fs.h> /* for BLKGETSIZE */
#include <stdbool.h>
#include <stddef.h>

#define RPMB_KEY_STDSIZE 32
#define RPMB_DAT_BLKSZ 256 // user dat
#define RPMB_BLKSZ 512 // transfer data frame
#define RPMB_WR_BLK_MAX 32 // once write blocks num max

#define printz(format, ...) \
    fprintf(stderr, "[%s:%d]" format, __FUNCTION__, __LINE__, ##__VA_ARGS__)

int do_rpmb_write_key(int dev_fd, char *p_rpmb_key, unsigned int key_size);
int do_rpmb_read_counter(int dev_fd, unsigned int *p_counter);
int do_rpmb_read_block(int dev_fd, unsigned short addr, unsigned int blocks_cnt, char *p_out, unsigned int outbuf_size, char *p_rpmb_key, unsigned int rpmb_keysize);
int do_rpmb_write_block(int dev_fd, unsigned short addr, char *p_in, unsigned int in_len, char *p_rpmb_key, unsigned int rpmb_keysize);

#ifdef __cplusplus
}
#endif
#endif